﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GraphicSVCUtil
{
    public partial class SVCUtil : Form
    {
        public SVCUtil()
        {
            InitializeComponent();
        }

        private void btnBrowseWSDL_Click(object sender, EventArgs e)
        {
            if (ofdBrowseWSDL.ShowDialog() == DialogResult.OK)
                this.txtWSDLPath.Text = ofdBrowseWSDL.FileName;

        }

        private void btnChooseOutputPath_Click(object sender, EventArgs e)
        {
            if (fbdChooseOutputPath.ShowDialog() == DialogResult.OK)
                this.txtOutputPath.Text = fbdChooseOutputPath.SelectedPath;
        }

        private void btnCreateClass_Click(object sender, EventArgs e)
        {
            //input validation
            if (this.txtClassName.Text.Length > 0 && this.txtOutputPath.Text.Length > 0 && this.txtWSDLPath.Text.Length > 0)
            {
                //creating the svcutilexec object
                SVCUTILexec Execute = new SVCUTILexec();
                FileInfo fiSVCUTIL = new FileInfo(Execute.strExecutionPath + "\\svcutil.exe");
                //validating svcutil is in the common sdk location
                if (fiSVCUTIL.Exists)
                {
                    //assigning parameters
                    Execute.strClassName = this.txtClassName.Text;
                    Execute.strOutputPath = this.txtOutputPath.Text;
                    Execute.strWSDLInputFilePath = this.txtWSDLPath.Text;
                    if (this.ddlLanguage.SelectedItem.ToString() == "C#")
                        Execute.bUseCSharp = true;

                    //executing the command
                    Execute.SVCUTILExecute();
                }
                else
                {
                    MessageBox.Show("Please make sure svcutil is located in the default SDK path" 
                       +" \"C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\bin\"", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please fill out all the required paths", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {   
            this.txtClassName.Text = "";
            this.txtOutputPath.Text = "";
            this.txtWSDLPath.Text = "";
        }
    }
}
